package main

import (
	"gitee.com/zhangyafeii/logo"
	"time"
)

func main() {
	//example1()
	consoleExample()
	//fileExample()
	//consoleFileExample()
}

func example1()  {
	log := logo.New()
	log.Debug("debug 测试信息")
	log.Trace("debug 测试信息")
	log.Info("debug 测试信息")
	log.Warning("debug 测试信息")
	log.Error("debug 测试信息")
}

func fileExample()  {
	log := logo.NewFileLogger(logo.DebugLevel, "log", "mylog.log",
		logo.WithMaxFileSize(10 * 1024 * 1024),
		logo.WithSplitAge(7 * 24 * 3600),
		logo.WithMaxCount(5, 1),
		logo.WithCheckTime(time.Hour),
	)
	log.SetEncoder(logo.JsonEncoder)
	for i := 0; i< 10000 ; i++ {
		log.Debug("debug 测试信息")
		log.Trace("debug 测试信息")
		log.Info("debug 测试信息")
		log.Warning("debug 测试信息")
		log.Error("debug 测试信息")
	}
	time.Sleep(5 * time.Second)
}

func consoleExample()  {
	log := logo.NewConsoleLogger(logo.DebugLevel)
	log.SetPrefix("[LOGO]")
	log.SetFileInfo(logo.WarningLevel)
	for i := 0; i< 10000 ; i++ {
		log.Debug("debug 测试信息")
		log.Trace("debug 测试信息")
		log.Info("debug 测试信息")
		log.Warning("debug 测试信息")
		log.Error("debug 测试信息")
	}
	//	[LOGO] 2020/07/05 - 14:50:59.729  ▶ [Debug] debug 测试信息
	//	[LOGO] 2020/07/05 - 14:50:59.729  ▶ [Trace] debug 测试信息
	//	[LOGO] 2020/07/05 - 14:50:59.729  ▶ [Info] debug 测试信息
	//	[LOGO] 2020/07/05 - 14:50:59.729 E:/go/project/src/logo/example/main.go:47 ▶ [Warning] debug 测试信息
	//	[LOGO] 2020/07/05 - 14:50:59.729 E:/go/project/src/logo/example/main.go:48 ▶ [Error] debug 测试信息
}

func consoleFileExample()  {
	log := logo.NewConsoleFileLogger(logo.DebugLevel,logo.WarningLevel, "log", "mylog.log",
		logo.WithMaxFileSize(10 * 1024 * 1024),
		logo.WithSplitAge(24 * 3600),
		logo.WithMaxAge(7 * 24 * 3600),
		logo.WithCheckTime(time.Hour),
	)
	for i := 0; i< 10000 ; i++ {
		log.Debug("debug 测试信息")
		log.Trace("debug 测试信息")
		log.Info("debug 测试信息")
		log.Warning("debug 测试信息")
		log.Error("debug 测试信息")
	}
	time.Sleep(5 * time.Second)
}

